package com.hzsai.converters;

import com.hzsai.pojo.User;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;

/**
 * hzsai 2019/7/25
 * usage:
 **/
@Component
public class StringToUserConverter implements Converter<String, User> {
    @Nullable
    @Override
    public User convert(String str) {

        User user = new User();

        // hzsai_123456_23
        String[] strArr = str.split("_");
        user.setUsername(strArr[0]);
        user.setPassword(strArr[1]);
        user.setAge(Integer.parseInt(strArr[2]));

        return user;
    }
}
